﻿using Styx.Common;
using Styx.CommonBot;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

namespace TuanHA_Monk_Special_Edition_Extreme_PvP
{
    public partial class Classname
    {
        #region BrewMasterRotation

        private Composite BrewMasterRotation()
        {
            return new PrioritySelector(
                new Action(delegate
                               {
                                   if (THSettings.Instance.AutoTarget && !Me.Mounted &&
                                       Me.CurrentTarget != null && UnitAttack != null &&
                                       Me.CurrentTarget != UnitAttack &&
                                       UnitAttack.Combat && //Make sure don't aggro more
                                       (Me.CurrentTarget.Distance - 5 > UnitAttack.Distance ||
                                        !Me.CurrentTarget.InLineOfSpellSight ||
                                        !Me.CurrentTarget.IsAlive ||
                                        !Me.CurrentTarget.Combat && Me.Combat))
                                   {
                                       Logging.Write(LogLevel.Diagnostic, "Select new Target");
                                       UnitAttack.Target();
                                   }

                                   //target the lowest threat unit
                                   if (THSettings.Instance.AutoTarget && Me.CurrentTarget != null &&
                                       Me.CurrentTarget.IsValid && GetUnitLowThreat() &&
                                       _unitLowThreat.IsValid && Me.CurrentTarget != _unitLowThreat &&
                                       Me.CurrentTarget.ThreatInfo.RawPercent < _unitLowThreat.ThreatInfo.RawPercent)
                                   {
                                       _unitLowThreat.Target();
                                       Logging.Write(LogLevel.Diagnostic, "Switch to Lowest Threat Target");
                                   }

                                   //target the lowest threat unit
                                   if (THSettings.Instance.AutoTarget && Me.CurrentTarget == null &&
                                       GetUnitLowThreat() &&
                                       _unitLowThreat.IsValid)
                                   {
                                       _unitLowThreat.Target();
                                       Logging.Write(LogLevel.Diagnostic, "Target  Lowest Threat Unit");
                                   }

                                   //Hold dps on Dungeon or Raid
                                   if ((Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) &&
                                       Me.CurrentTarget != null &&
                                       !Me.CurrentTarget.Combat)
                                   {
                                       return RunStatus.Success;
                                   }

                                   return RunStatus.Failure;
                               }),
                ////Trying to stop bot movement while casting
                //new Decorator(
                //    ret =>
                //    Me.IsCasting,
                //    new Action(delegate { return RunStatus.Success; })
                //    ),
                //But first, facing target
                new Decorator(
                    ret =>
                    THSettings.Instance.AutoFace &&
                    Attackable(Me.CurrentTarget) &&
                    !Blacklist.Contains(Me.CurrentTarget, BlacklistFlags.All) &&
                    (Me.CurrentTarget.IsTargetingMeOrPet ||
                     Me.CurrentTarget.IsTargetingMyPartyMember ||
                     Me.CurrentTarget.IsTargetingMyRaidMember) &&
                    Me.CurrentTarget.Distance < 15 &&
                    !Me.Mounted &&
                    !IsOverrideModeOn &&
                    !Me.IsFacing(Me.CurrentTarget),
                    new Action(delegate
                                   {
                                       Me.CurrentTarget.Face();
                                       return RunStatus.Failure;
                                   })
                    ),
                //Starting the movement right here
                //MovementMoveBehind(ret => Me.CurrentTarget),
                MovementMoveToMelee(ret => Me.CurrentTarget),
                MovementMoveStop(ret => Me.CurrentTarget, 3),
                //DPS Rotation Here
                //WriteTargetInfo(),
                PickHealingSphere(),
                PickChiSphere(),
                SpearHandStrike(),
                SetAutoAttack(),
                FortifyingBrew(),
                DampenHarm(),
                ElusiveBrew(),
                ElusiveBrewStack(),
                PurifyingBrew(),
                ChiBrew(),
                ZenMeditation(),
                TigersLustMe(),
                RollBrew(),
                ChiTorpedo(),
                ProvokeBrew(),
                LeeroftheOxBrew(),
                TouchofDeath(),
                AvertHarm(),
                Clash(),
                LegSweepInterrupt(),
                ChargingOxWaveInterrupt(),
                ParalysisInterrupt(),
                CracklingJadeLightningPushBack(),
                Transcendence(),
                DiffuseMagic(),
                LegSweepMeLowHP(),
                ChargingOxWaveMeLowHP(),
                ParalysisMeLowHP(),
                QuakingPalmMeLowHP(),
                HealingSphereUrgent(),
                Disable(),
                InvokeXuen(),
                GrappleWeapon(),
                ExpelHarm(),
                Guard(),
                SummonBlackOxStatue(),
                KegSmashDebuff(),
                KegSmashAoE(),
                JabBrewCapEnergy(),
                JabBrewNearCapEnergy(),
                RushingJadeWindBrew(),
                BlackoutKickShuffle(),
                DizzyingHaze(),
                TigerPowerBuff(),
                BreathofFire(),
                ChiWaveMe(),
                ZenSphereMe(),
                SpinningCraneKickBrew(),
                HealingSphereCombat(),
                SpinningFireBlossom(),
                HealingSphereNoCombat(),
                HealingSphereCombatBeforeReachingEnemy(),
                BlackoutKickBrewDumpChi(),
                JabBrew(),
                TigerPowerBrew(),
                LegacyoftheEmperor()
                //WriteDebug("LegacyoftheEmperor"),
                //PathofBlossoms()
                );
        }

        #endregion
    }
}